{% extends "base.html" %}

{% block title %}添加用户 - 后台管理系统{% endblock %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">添加用户</h1>
    <div class="btn-toolbar mb-2 mb-md-0">
        <div class="btn-group me-2">
            <a href="{{ url_for('users') }}" class="btn btn-sm btn-outline-secondary">
                <i class="fas fa-arrow-left"></i> 返回列表
            </a>
        </div>
    </div>
</div>

{% with messages = get_flashed_messages(with_categories=true) %}
    {% if messages %}
        {% for category, message in messages %}
            <div class="alert alert-{{ 'danger' if category == 'error' else category }} alert-dismissible fade show" role="alert">
                {{ message }}
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        {% endfor %}
    {% endif %}
{% endwith %}

<div class="row justify-content-center">
    <div class="col-md-10">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">用户信息</h5>
            </div>
            <div class="card-body">
                <form method="POST">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="username" class="form-label">用户名 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="username" name="username" required>
                            <div class="form-text">用户名必须唯一</div>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label for="userPhone" class="form-label">手机号</label>
                            <input type="tel" class="form-control" id="userPhone" name="userPhone" pattern="[0-9]{11}" placeholder="请输入11位手机号">
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="userEmail" class="form-label">邮箱</label>
                            <input type="email" class="form-control" id="userEmail" name="userEmail" placeholder="请输入邮箱地址">
                        </div>
                        <div class="col-md-6 mb-3">
                            <label for="userCode" class="form-label">用户类型</label>
                            <select class="form-select" id="userCode" name="userCode">
                                <option value="0" selected>普通用户</option>
                                <option value="1">商家</option>
                                <option value="2">禁用用户</option>
                            </select>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-4 mb-3">
                            <label for="userAge" class="form-label">年龄</label>
                            <input type="number" class="form-control" id="userAge" name="userAge" min="1" max="120" placeholder="请输入年龄">
                        </div>
                        <div class="col-md-4 mb-3">
                            <label for="userGender" class="form-label">性别</label>
                            <select class="form-select" id="userGender" name="userGender">
                                <option value="">请选择</option>
                                <option value="男">男</option>
                                <option value="女">女</option>
                                <option value="其他">其他</option>
                            </select>
                        </div>
                        <div class="col-md-4 mb-3">
                            <label for="userPoints" class="form-label">初始积分</label>
                            <input type="number" class="form-control" id="userPoints" name="userPoints" min="0" value="1000" placeholder="默认1000积分">
                            <div class="form-text">新用户默认获得1000积分</div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="userCity" class="form-label">所在城市</label>
                            <input type="text" class="form-control" id="userCity" name="userCity" placeholder="请输入城市名称">
                        </div>
                        <div class="col-md-6 mb-3">
                            <label for="userSignature" class="form-label">个性签名</label>
                            <input type="text" class="form-control" id="userSignature" name="userSignature" placeholder="请输入个性签名" maxlength="100">
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-12">
                            <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                                <a href="{{ url_for('users') }}" class="btn btn-secondary me-md-2">取消</a>
                                <button type="submit" class="btn btn-primary">
                                    <i class="fas fa-save"></i> 保存用户
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}